<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
    <link rel="stylesheet" href="./css/register.css">
</head>
<body>
    <div class="main">
        <div class="register w">
            <div class="left">
                <img src="./images/chahua.png" alt="">
            </div>
            <div class="right">
                <div class="from">
                    <div class="title">
                        <h2>盈链科技</h2>
                        <span>盈聚智慧，链通价值</span>
                    </div>
                    <div class="login">
                        <img src="./images/yonghu.png" alt="">
                        <input type="mobile" placeholder="请使用手机号码注册" id="mobile" maxlength="11">
                    </div>
                    <div class="Verification">
                        <img src="./images/mima.png" alt="">
                        <input type="password" name="password" placeholder="登陆密码" id="password">
                        <img class="passwordeye" src="./images/eye.png" alt="">
                    </div>
                    <div class="Verification">
                        <img src="./images/mima.png" alt="">
                        <input type="password" name="passwords" placeholder="确认密码" id="passwords">
                        <img class="passwordeye" src="./images/eye.png" alt="">
                    </div>
                    <div class="Verification1">
                        <img src="./images/code-1.png" alt="">
                        <input type="mobilecode" placeholder="请输入验证码" name="code" id="code" maxlength="6">
                        <a href="#" id="oncode">获取验证码</a>
                    </div>
                    <div class="yes">
                        <span>已有账号?</span>
                        <a href="./login.php">立即登录</a>
                    </div>
                    <a href="#" id="sub"><div class="immediatelyLogin">
                        立即注册
                    </div></a>
                </div>
            </div>
        </div>      
    </div>
</body>
</html>
<script src="./js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="../public/lib/layer/2.4/layer.js"></script>
<script type="text/javascript">
$(function(){
    $('#oncode').click(function(){
        var mobile = $('#mobile').val();
        if (mobile == false) {
            layer.msg('请填写手机号！');
            return false;
        }else if(isPoneAvailable(mobile) == false){
            return false;
        }
        var url = 'http://'+document.domain+"/index/login/sendCaptcha";
        $.ajax({
            type: 'POST',
            url: url,
            data:{mobile:mobile,type:1},
            dataType: 'json',
            success: function(data){

            },
            error:function(data) {
                // console.log(data.msg);
            },
        })
    })
    $('#sub').click(function(){
        var mobile = $('#mobile').val();
        var password = $('#password').val();
        var passwords = $('#passwords').val();
        var code = $('#code').val();
        if (mobile == false) {
            layer.msg('请填写手机号！');
            return false;
        }
        if (isPoneAvailable(mobile) == false) {
            layer.msg('请填写有效的手机号！');
            return false;
        }
        if (password == false) {
            layer.msg('请填写密码！');
            return false;   
        }
        if (password != passwords) {
            layer.msg('密码不一致！');
            return false;
        }
        if (code == false) {
            layer.msg('请填写验证码');
            return false;
        }
        var url = 'http://'+document.domain+"/index/login/register";
        $.ajax({
            type: 'POST',
            url: url,
            data:{mobile:mobile,password:password,code:code,type:1},
            dataType: 'json',
            success: function(data){
                if (data.stats==false) {
                    layer.msg(data.msg);
                }else{
                    layer.msg(data.msg);
                    var memberArr;
                    if (localStorage.member) {
                        memberArr = JSON.parse(localStorage.getItem("member"));
                        if (memberArr.length == 8) {
                            memberArr.unshift($(this).val());
                            memberArr.pop();
                        } else {
                        memberArr.unshift($(this).val());
                        }
                    } else {
                        memberArr = [];
                        memberArr[0] = $(this).val();
                    }
                    localStorage.setItem("member", JSON.stringify(memberArr));
                    window.location.href="index.html";
                }
            },
            error:function(data) {
                
            },
        })
    })
})
function isPoneAvailable(data) {
    var reg = /^(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/;
    if (!reg.test(data)) {
        layer.msg('请填写有效的手机号！');
        return false;
    } else {
        return data;
    }

}
</script>